// AddFeedWizardDlg.cpp : implementation file
//

#include "stdafx.h"
#include "tinypp.h"
#include "AddFeedWizardDlg.h"
#include "RSSFeed.h"
#include "RSSParser.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAddFeedWizardDlg dialog


CAddFeedWizardDlg::CAddFeedWizardDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddFeedWizardDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddFeedWizardDlg)
	m_strFeedUrl = _T("http://localhost/temp.xml");
	m_strFeedGroupName = _T("");
	m_strFeedTitle = _T("a title for test");
	m_bGetFromInternet = TRUE;
	//}}AFX_DATA_INIT
}


void CAddFeedWizardDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddFeedWizardDlg)
	DDX_Text(pDX, IDC_EDIT1, m_strFeedUrl);
	DDX_CBString(pDX, IDC_COMBO1, m_strFeedGroupName);
	DDX_Text(pDX, IDC_EDIT2, m_strFeedTitle);
	DDX_Check(pDX, IDC_CHECK1, m_bGetFromInternet);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddFeedWizardDlg, CDialog)
	//{{AFX_MSG_MAP(CAddFeedWizardDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddFeedWizardDlg message handlers

void CAddFeedWizardDlg::OnOK() 
{
	UpdateData(TRUE);
	if(m_bGetFromInternet){
		//todo: a generic way to get properities from internet
		RSSFeed feed;
		RSSParser parser;
		
		if ( URLDownloadToFile( NULL, m_strFeedUrl, _T("temp.xml"),0, NULL ) != S_OK ){
            MessageBox("Update RSS source failed");
			return;
		}
		
		if( !parser.ParseFile(_T("temp.xml"),&feed) )
			return;
		m_strFeedTitle=feed.GetTitle();
	}

	UpdateData(FALSE);
	CDialog::OnOK();
}
